﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.DynamicProxy;
using Castle.MicroKernel;
using Castle.Model;
using Castle.Windsor;

namespace CastleIocTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Castle.Windsor.IWindsorContainer container = new Castle.Windsor.WindsorContainer("CastleObjMap.xml");
            IHello<User> r = (IHello<User>)container[typeof(IHello<User>)];
            Console.WriteLine(r.SayHello(new User()));
            IHello<SuperUser> rs = (IHello<SuperUser>)container[typeof(IHello<SuperUser>)];
            Console.WriteLine(rs.SayHello(new SuperUser()));
            Console.Read();

        }
    }

    public interface IHello<TEntity>where TEntity: IUser 
    {
        string SayHello(TEntity user);
    }

    public class Hello<TEntity> : IHello<TEntity> where TEntity : IUser
    {
        public string SayHello(TEntity user)
        {
            return user.GetName();
        }
    }

    public interface IUser
    {
        string GetName();
    }

    public class User:IUser
    {
        public  string GetName()
        {
            return "Wusong";
        }
    }

    public class SuperUser : IUser
    {
        public string GetName()
        {
            return "SuperUser";
        }
    }
        
}
